import * as path from 'path'

export default {
    // 获取工程根目录，src所在的目录
    getProjectPath (workDir: any) {
        let projectName

        let cb = (workDir: any) => {
            // 如果当前目录没有src，则不断返回上一层
            if (/node_modules$/.test(workDir)) {
                return path.join(workDir, '../')
            }
            // 如果当前目录没有src，则不断返回上一层
            if (!/(src|src(\/|\\))$/.test(workDir)) {
                projectName = path.join(workDir, '../')
                // console.log('projectName', projectName);
                return cb(projectName)
            }
            // 如果当前目录是src，则返回该目录
            return path.join(workDir, '../')
        }

        return cb(workDir)
    }
}